/**
 * 
 */
package br.com.fatesg.www.dao;

import org.hibernate.Query;
import org.hibernate.Session;

import br.com.fatesg.www.entidade.Residuo;
import br.com.fatesg.www.util.HibernateUtil;

/**
 * @author eder
 * 
 */
public class ResiduoDAO extends DAO<Residuo, Long> {

	Session session;

	public ResiduoDAO(Session session) {
		super(session);
		this.session = session;
	}

/*	public Long salvar(Residuo residuo) {

		session.beginTransaction();
		Long id = super.salvar(residuo);
		session.getTransaction().commit();
		session.flush();
		session.close();

		return id;
	}

	public void atualizar(Residuo residuo) {
		session.beginTransaction();
		super.atualizar(residuo);
		session.getTransaction().commit();
		session.flush();
		session.close();
	}

	public void excluir(Residuo residuo) {
		session.beginTransaction();
		super.excluir(residuo);
		session.getTransaction().commit();
		session.flush();
		session.close();
	}

	@SuppressWarnings("rawtypes") 
	public List<Residuo> listar(Class clazz) {
		if (!session.isOpen()) {
			session = HibernateUtil.getSessionFactory().openSession();
			super.session = session;
		}
		
		return super.listar(clazz);
	}*/
	public Residuo obter(Long id) {
		if (!session.isOpen()) {
			session = HibernateUtil.getSessionFactory().openSession();
		}
		Query query = session.createQuery("from Residuo where id = :id");
		query.setParameter("id", id);
		query.setMaxResults(1);
		return (Residuo) query.uniqueResult();
	}
	

	@Override
	public Session getSession() {
		return session;
	}

}
